﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>Container</title>
</head>

<body>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <form id="form-search" class="searcharea">
                <input type="text" class="inputword" name="word" title="关键字搜索" placeholder="关键字搜索" value="">
                <span class="title">项目：</span>
                <select name="projectId">
                    <option value="0">未选择</option>
                </select>

                <span class="title">服务：</span>
                <select name="serviceId">
                    <option value="0">未选择</option>
                </select>

                <span class="title">状态：</span>
                <select name="state">
                    <option value="-1" selected>所有状态</option>
                    <option value="0">待运行</option>
                    <option value="1">运行中</option>
                    <option value="3">成功</option>
                    <option value="4">失败</option>
                </select>

                <input type="button" class="btnsearch" onclick="_readpagedata(1);" value="查询">
                <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                    href="javascript:location.replace(location.href);" title="刷新"><i
                        class="Hui-iconfont">&#xe68f;</i></a>
            </form>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                    <tr class="text-c">
                        <th width="50">ID</th>
                        <th>服务信息</th>
                        <th>容器名称</th>
                        <th>容器ID</th>
                        <th width="150">创建</th>
                        <th width="120">地址</th>
                        <th width="80">端口</th>
                        <th width="80">运行状态</th>
                        <th width="60">操作</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="pagenumarea" class="pagenumarea"></div>
    </div>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../lib/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->


    <script src="../lib/api.js"></script>
    <link href="../lib/page.min.css" rel="stylesheet" />
    <script src="../lib/page.min.js"></script>

    <script>

        var pageobject = null;

        $(window).ready(function () {


            _readpagedata(1);

            _readservice(true);

            _readproject(true);

            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });
        });

        function _readpagedata(page) {

            if (page == 1) {
                $("#pagenumarea").empty();
            }

            var dataobj = $("#form-search").parseForm();
            dataobj.page = page;
            dataobj.size = 20;

            _apipost("/api/spider/manage/ReadAppInfo", true, JSON.stringify(dataobj), function (code, obj) {
                if (code == 200) {
                    var datas = obj.items;
                    _showpagedata(datas);
                    if (pageobject == null || page == 1) {
                        pageobject = new Page({
                            el: '#pagenumarea',
                            nums: obj.totalCount,//总数
                            counts: 20,//每页大小
                            defaultPage: 1,
                            showHeadFoot: false, // 显示首页尾页
                            head: '首', // 更改首页文字
                            foot: '尾', // 更改尾页文字
                            jumpToOrder: true, // 跳转到指定页
                            showNowAndAll: true, // 当前页/共几页
                            prev: "上一页",
                            next: "下一页",
                            clickEvent: function (currectPage, _this) {
                                _readpagedata(currectPage);
                            }
                        });
                    }
                }
            });
        }

        function _showpagedata(datas) {

            $("table").find("tbody").empty();
            // <th width="50">ID</th>
            //             <th width="80">容器</th>
            //             <th width="80">容器ID</th>
            //             <th width="150">创建</th>
            //             <th width="120">地址</th>
            //             <th width="80">端口</th>
            //             <th width="80">运行状态</th>
            //             <th >项目信息</th>
            var hstr = "";
            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];
                var htmlStr = '<tr class="text-c">';
                htmlStr += '<td>' + item.id + '</td>';
                htmlStr += '<td class="fleft">' + item.projectName + '-' + item.serviceCode + '-' + item.model + '</td>';
                htmlStr += '<td class="fleft"><a hreaf="javascript:;" onclick="viewcharts(\'' + item.name + '\')">' + item.name + '</a></td>';
                if (item.appId) {
                    if (item.appId.length > 0) {
                        htmlStr += '<td><a href="javascript:;" onclick="_apprefush(this);" dataid="' + item.appId + '">' + item.appId + '</a></td>';
                    } else {
                        htmlStr += '<td></td>';
                    }
                } else {
                    htmlStr += '<td></td>';
                }

                htmlStr += '<td>' + item.create + '</td>';
                htmlStr += '<td>' + item.address + '</td>';
                htmlStr += '<td>' + item.ports + '</td>';
                htmlStr += '<td>' + item.runState.RunState() + '</td>';
                if(item.runState!=1){
                    htmlStr += '<td><a href="javascript:;" dataid="'+item.id+'" onclick="_funcremove(this);">删除</a></td>';
                }else{
                    htmlStr += '<td></td>';
                }

                htmlStr += '</tr>';
                hstr += htmlStr;
            }
            $("table").find("tbody").append(hstr);
        }


        //删除这个不再运行的容器
        function _funcremove(elc){
            var dataid=$(elc).attr('dataid');
            _apipost('/api/spider/appInfo/'+dataid+'/remove',false,'',function(code,obj){
                if(code==200){
                    $(elc).html('已删除');
                }
            });
        }

        //刷新状态
        function _apprefush(elc) {
            var dataid = $(elc).attr('dataid');
            _apipost("/api/spider/manage/" + dataid + "/appRefush", true, "", function (code, obj) {
                if (code == 200) {
                    $(elc).html("已查询");
                }
            });
        }



        function viewcharts(name) {
            _showedit('查看', '../echarts/app.html', name, '100%', '80%');
        }


    </script>

</body>

</html>